import java.lang.reflect.Array;
import java.nio.channels.NonWritableChannelException;
import java.util.Arrays;

public class Solution {
    public int searchInsert(int[] nums, int target){
        int index= Arrays.binarySearch(nums,target);
        if(index>=0){
            return index;
        }else {
            return  -index-1;

        }

    }

    public static void main(String[] args) {
        Solution solution=new Solution();

        int[] nums1 = {1, 3, 5, 6};
        int target1 = 5;
        System.out.println("示例1："+solution.searchInsert(nums1,target1));

        int[] nums2= {1, 3, 5, 6};
        int target2 = 2;
        System.out.println("示例2："+solution.searchInsert(nums2,target2));

        int[] nums3 = {1, 3, 5, 6};
        int target3 = 7;
        System.out.println("示例3: " + solution.searchInsert(nums3, target3));
    }
}
